package com.phiture.erp.basic.web.controller.api;

import cn.hutool.core.collection.CollUtil;
import com.phiture.erp.basic.api.pojo.resp.ErpUserCustomizeConfigResp;
import com.phiture.erp.basic.api.service.ErpUserCustomizeConfigApi;
import com.phiture.erp.basic.core.service.ErpUserCustomizeConfigService;
import com.phiture.erp.basic.dal.entity.ErpUserCustomizeConfigDO;
import com.phiture.erp.basic.web.convert.ErpUserCustomizeConfigConvertMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author YH
 * @date 2025-05-08-9:33
 */

@Service
@RequiredArgsConstructor
public class ErpUserCustomizeConfigApiServiceImpl implements ErpUserCustomizeConfigApi {
    private final ErpUserCustomizeConfigService userCustomizeConfigService;

    @Override
    public ErpUserCustomizeConfigResp getUserCustomizeConfig(String configKey) {
        ErpUserCustomizeConfigDO config = userCustomizeConfigService.getUserCustomizeConfig(configKey);
        return ErpUserCustomizeConfigConvertMapper.INSTANCE.toErpUserCustomizeConfigResp(config);
    }

    @Override
    public List<ErpUserCustomizeConfigResp> getUserCustomizeConfigList(Collection<String> configKeys) {
        List<ErpUserCustomizeConfigDO> list = userCustomizeConfigService.getUserCustomizeConfigList(configKeys);
        return ErpUserCustomizeConfigConvertMapper.INSTANCE.toErpUserCustomizeConfigRespList(list);
    }

    @Override
    public Map<String, ErpUserCustomizeConfigResp> getUserCustomizeConfigMap(Collection<String> configKeys) {
        List<ErpUserCustomizeConfigResp> list = getUserCustomizeConfigList(configKeys);
        if(CollUtil.isEmpty(list)){
            return Collections.emptyMap();
        }
        return list.stream().collect(Collectors.toMap(ErpUserCustomizeConfigResp::getConfigKey, obj-> obj));
    }
}
